package com.hh.vietnameseproject.ui.changeplan

import android.app.Activity
import android.app.ActivityOptions
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.hh.vietnameseproject.R
import com.hh.vietnameseproject.logic.model.WordList
import com.hh.vietnameseproject.ui.changeplandetails.PlanDetailsActivity
import java.util.ArrayList

class PlanRecyclerViewAdapter(val context: Context,val list: ArrayList<WordList>): RecyclerView.Adapter<PlanRecyclerViewAdapter.ViewHolder>() {



    class ViewHolder(itemView: View) :RecyclerView.ViewHolder(itemView) {
        val imageView = itemView.findViewById<ImageView>(R.id.planItemImage)
        val text = itemView.findViewById<TextView>(R.id.planItemText)

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.plan_recyclerview_item,parent,false)
        return ViewHolder(view)
    }

    override fun getItemCount() = list.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        //Glide
        //Glide.with(context).load(list[position].image).into(holder.imageView)
        holder.imageView.setImageResource(list[position].image)
        holder.text.setText(list[position].type)
        holder.itemView.setOnClickListener {
            val intent = Intent(context,PlanDetailsActivity::class.java)
            val pair = android.util.Pair<View,String>(holder.imageView,"image")
            val activityOptions = ActivityOptions.makeSceneTransitionAnimation(context as Activity?,pair)
            intent.putExtra("text",list[position].type)
            intent.putExtra("image",list[position].image)
            intent.putExtra("id",list[position].id)
            intent.putExtra("count",list[position].count)
            context.startActivity(intent,activityOptions.toBundle())
        }
    }
}